import subprocess
import json

def query_user_by(id:int):
    print(f'id:{id}')
    try:
        # 调用submodule_demo下的query_user.py
        result = subprocess.run(
            ["python", "-m", "submodule_demo.user.query_user", str(id)],
            capture_output=True,
            text=True,
            check=True
        )
        json_output = result.stdout.strip()
        print("子模块JSON输出:")
        print(json_output)
            
        # 解析JSON
        parsed_data = json.loads(json_output)
            
        # 返回原始结果和子模块执行结果
        return {
            "data": parsed_data,
            "code": 200,
            "message": "success"
        }
    except subprocess.CalledProcessError as e:
        print(f"执行子模块时出错: {e}")
        print(f"错误输出: {e.stderr}")
        return {
            "data": None,
            "code": 500,
            "message": f"执行子模块失败: {e.stderr}"
        }